/** \file */
/// \addtogroup Wally
/// \{
/**
*	\brief Library for I2C (TWI) peripherals
*	Currently supports:
*	DS1307 Real Time Clock
*	FM24C64B External RAM
*/

#ifndef __i2c_peripherals_h__
#define __i2c_peripherals_h__

#include "Wally.h"

// Macro definitions

// Functions
/**
*	\brief Gets the time for the real-time clock.
*	Queries the RTC over I2C fof the current time.
*/
void getRTCtime(uint8_t *);

/**
*	\brief Gets the time for the real-time clock.
*	Adjusts the time of the RTC
*	Queries the RTC over I2C fof the current time.
*/
void setRTCtime(void);

/**
*	\brief Converts decimal to binary coded decimal (bcd)
*	\param decimal value
*	\return binary coded decimal value
*/
uint8_t dec2bcd(uint8_t);

/**
*	\brief Converts binary coded decimal (bcd) to decimal.
* 	\param binary coded decimal value
*	\return decimal value
*/
uint8_t bcd2dec(uint8_t);

/**
*	\brief Write a byte to external RAM connected via I2C
*
*	\param word address: Data address (16bit)
*	\param byte data: Data to wite
*
*/
void writeRAM(uint16_t, uint8_t);

/**
*	\brief Read a byte from external RAM connected via I2C
*
*	\param word address: Data address (16bit)
*	\return byte data: Data to wite
*
*/
uint8_t readRAM(uint16_t);


// I2C addresses definition s
#define I2CaddrRTC 0x68 			///< I2C address for RTC
#define I2CaddrRAM 0x50				///< I2C address for RAM (with all address pins unconnected - low by default)


//extern uint8_t example;	// extern means we don't create the variable here - done in library

#endif /* __i2c_peripherals_h__ */

/// \}
